package com.freecloud.javabasics.thread.condition;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * @Author: maomao
 * @Date: 2020-02-22 13:06
 */
public class ConditionNotify implements Runnable {

    private Lock lock;
    private Condition condition;

    public ConditionNotify(Lock lock, Condition condition) {
        this.lock = lock;
        this.condition = condition;
    }

    @Override
    public void run() {
        try{
            lock.lock();//竞争锁
            System.out.println("begin - ConditionNotify");
            condition.signal();//唤醒阻塞状态的线程  与sync
            System.out.println("end - ConditionNotify");
        }finally {
            lock.unlock();//释放锁
        }
    }
}
